package crm.model.teacherPC.statistic;

import java.util.Arrays;
import java.util.TreeMap;

import crm.model.teacherPC.net.StudentPC;

public class Statistic {
	StudentPC student;
	public TreeMap <String, StatisticValue> map;
	public long sumTime = 0;
	private long lastRefreshTime;
	public Statistic(StudentPC student) {
		this.student=student;
		map = new TreeMap<String, StatisticValue>();
		lastRefreshTime = System.currentTimeMillis();
	}

	public void refresh() {
		sumTime += (System.currentTimeMillis() - lastRefreshTime);

		String windowName = student.getForegroundWindowName();
		
		if (map.containsKey(windowName)){
			map.get(windowName).addTime((System.currentTimeMillis() - lastRefreshTime));
		}else {
			map.put(windowName, new StatisticValue(System.currentTimeMillis() - lastRefreshTime, windowName, this));
		}
		
		lastRefreshTime = System.currentTimeMillis();
	}
	public Object[] getSortedArray(){
		Object [] array = map.values().toArray();
		Arrays.sort(array);
		return array;
	}
}
